
<?php
	include_once("adb.php");
	
	class cho extends adb{
		function cho(){
			adb::adb();
		}
		/**
		*query all cho in the table and store the dataset in $this->result	
		*@return if successful true else false
		*/
		
		function get_all_cho(){
			$query="select * from cho";
			return $this->query($query);
		}
		
		function add_cho($cho_name,$subdistrict_id,$pin_number){
			//write the SQL query and call $this->query()
			$query="insert into cho (idcho, `cho_name`, subdistrict_id, pin_number) VALUES (NULL,'$cho_name',$subdistrict_id,$pin_number)";  
			return $this->query($query);
		}
		/**
		*updates the record identified by id 
		*/
		function update_cho($idcho,$cho_name,$subdistrict_id,$pin_number){
			$query="update cho set cho_name='$cho_name',
						 subdistrict_id=$subdistrict_id, pin_number=$pin_number where 
							idcho=$idcho";
			if(!$this->query($query)){
				return false;
			}
			return true;
		}
		
		function delete_cho($idcho){
			$query = "delete from cho where idcho=$idcho";
			return $this->query($query);
		}
		
		function get_cho_id($id){
			$query="select * from cho where idcho=$id";
			if(!$this->query($query)){
				return false;
			}
			return $this->fetch();
		}
		
		function search_cho($cho_name){
			$query = "select * from cho where cho_name like '%$cho_name%'";
			return $this -> query($query);
		}
	}
	
?>




